package com.supermap.business.monitors;

import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.annotation.Reference;
import com.supermap.dataservice.util.JSONUtil;
import com.supermap.dubbo.api.monitor.MonitorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author lxs
 * @Title:监控接口层
 * @Description:
 * @date 2018/8/24  11:40
 */
@Controller
@RequestMapping("MonitorsController")
public class MonitorsController {
    /**
     * 使用指定类初始化日志对象，在日志输出的时候，可以打印出日志信息所在类
     */
    protected static final Logger logger = LoggerFactory.getLogger(MonitorsController.class);
    @Autowired
    private RegistryConfig registryConfig;
    @Reference(registry = "")
    private MonitorService monitorService;
    /**
     * 根据code获取当年的每个月的上传农情种类总数
     *
     * @param request
     * @return
     */
    @RequestMapping("/getAgrCropsByAreacode")
    @ResponseBody
    public JSONUtil getAgrCropsByAreacode(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
        String areacode = request.getParameter("areacode");
        return monitorService.getAgrCropNumsByAreacode(areacode);
    }

    /**
     * 各类服务对象总数量
     *
     * @param request
     * @return
     */
    @RequestMapping("/getSerObjListByAreacode")
    @ResponseBody
    public JSONUtil getSerObjListByAreacode(HttpServletRequest request) {
        String areaCode = request.getParameter("areaCode");
        return monitorService.getSerObjListByAreacode(areaCode);
    }

    /**
     * 获取当年当月的服务对象数量
     *
     * @param request
     * @return
     */
    @RequestMapping("/getSerObjListByAreacodeAndYearMonth")
    @ResponseBody
    public JSONUtil getSerObjListByAreacodeAndYearMonth(HttpServletRequest request) {
        String areaCode = request.getParameter("areaCode");
        return monitorService.getSerObjListByAreacodeAndYearMonth(areaCode);
    }

    /**
     * 根据code获取专家活跃度
     *
     * @param request
     * @return
     */
    @RequestMapping("/getActiveListByareaCode")
    @ResponseBody
    public JSONUtil getActiveListByareaCode(HttpServletRequest request) {
        String areaCode = request.getParameter("areaCode");
        return monitorService.getActiveListByareaCode(areaCode);
    }

    /**
     * 根据UserId获取对应评论
     *
     * @param request
     * @return
     */
    @RequestMapping("/getActiveCommmentListByuserId")
    @ResponseBody
    public JSONUtil getActiveCommmentListByareaid(HttpServletRequest request) {
        String userId = request.getParameter("userId");
        return monitorService.getActiveCommmentListByuserId(userId);
    }

    /**
     * 获取灾情 咨询 农情的每月的上传统计数
     * @param request
     * @return
     */
    @RequestMapping("/getAllList")
    @ResponseBody
    public JSONUtil getAllList(HttpServletRequest request){
        String areaCode = request.getParameter("areaCode");
        return  monitorService.getAllList(areaCode);
    }
}
